#pragma once
#include"MyRBTree.h"

namespace MYSPACE{
template<class K,class V>
class MyMap{
  struct MapKOfVCompare{
    const K& operator()(const std::pair<K,V> &data)
    {
      return data.first;
    }
  };
  private:
    RBTree<K,std::pair<K,V>,MapKOfVCompare> _RBTree;
  public:
    typedef typename RBTree<K,std::pair<K,V>,MapKOfVCompare>::iterator iterator;
    MyMap(){}
    std::pair<iterator,bool> insert(const std::pair<K,V> &data)
    {
      return _RBTree.insert(data);
    }
    V& operator[](const K& key)
    {
      iterator it = _RBTree.find(key);
      if(it != _RBTree.end())
      {
        return it->second;
      }
      else{
        auto p = _RBTree.insert(std::make_pair(key,V()));
        return p.first->second; 
      }
    }
    iterator find(const K& key)
    {
      _RBTree.find(key);
    }
    iterator begin()
    {
      return _RBTree.begin();
    }
    iterator end()
    {
      return _RBTree.end();
    }
};
}
